package com.show.controller;

import com.shop.entity.food.Food;
import com.shop.service.food.FoodServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("food")
public class FoodController {
    @Autowired
    private FoodServiceImpl foodService;
    @GetMapping("show")
    public Map<String, Object> show(){
        List<Food> list = foodService.queryAllFood();
        List<String> n = new ArrayList<>();
        List<Double> p = new ArrayList<>();
        for (Food food : list){
            n.add(food.getFoodclass());
            p.add(food.getPrice());
        }
        Map<String ,Object> map = new HashMap<>();
        map.put("xAxis",n);
        map.put("val",p);
        return map;
    }
    @GetMapping("show2")
    public List<Food> show2(){
        return foodService.queryAllFood();
    }
}
